package com.kksoft.readcm.activity;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

import com.kksoft.readcm.a.ItemAppObservable;
import com.kksoft.readcm.a.LoginAppObservable;
import com.kksoft.readcm.c.b;
import com.kksoft.readcm.d.j;
import com.kksoft.readcm.a.Appconfig;
import com.kksoft.readcm.objects.ac;
import com.kksoft.readcm.objects.GlobalVar;
import com.kksoft.readcm.objects.l;
import com.kksoft.readcm.objects.n;
import com.kksoft.readcm.objects.ReadListAdapter;
import com.kksoft.readcm.pro.R;
import com.kksoft.readcm.views.ErrorScreen;
import com.kksoft.readcm.views.FixedViewFlipper;
import com.kksoft.readcm.views.p;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Observable;
import java.util.Set;

public class ListViewActivity extends RilAppActivity
  implements b, com.kksoft.readcm.objects.af
{
  private FixedViewFlipper pViewFlipper;
  private ErrorScreen pErrorScreen;
  private FixedViewFlipper p2ViewFlipper;
  private Drawable pngSync;
  private Drawable pngBlank;
  private Drawable bgFilter;
  private Drawable bgFilterActive;
  private ImageView icFilter = null;     //old H
  private ImageButton btnClear = null;   //old I
  //private Button J = null;
  private boolean K = false;
  private ac L;
  private int M;
  private boolean N = false;
  private boolean O = false;
  private int P;
  private ProgressDialog pDialog;
  protected boolean a = false;
  protected String b = null;
  protected TextView c = null;
  protected LinearLayout d = null;
  protected ListView listview = null;      //old e
  protected ImageButton btnSync = null;    //old f
  protected ProgressBar progressbar = null;              //old g
  protected ImageButton btnSort = null;         //old h
  protected EditText edtFilter = null;
  protected Button j = null;
  protected n k;
  protected ReadListAdapter readlistadapter;
  protected Handler m;
  protected p n;
  protected int o;
  protected boolean p = false;
  private String z;

  static void c(ListViewActivity listviewactivity)
  {
      listviewactivity.showDialog(23);
      ListAsyncTask listTask = new ListAsyncTask(listviewactivity, com.kksoft.readcm.a.Appconfig.getThis(), listviewactivity.loadType(), listviewactivity.readlistadapter.d());
      Void avoid[] = new Void[0];
      AsyncTask asynctask = listTask.execute(avoid);
  }
  
  public static void clearFilter()  //old K
  {
    App.getSharedPreferences().edit().putString("filterReading", "").putString("filterCurrent", "").putString("filterRead", "").putString("filterTagDir", "").commit();
  }

  private void L()
  {
    this.N = true;
    Intent it = getIntent();
    if ((it != null) && (it.getBooleanExtra("launchSearch", false)))
      this.edtFilter.requestFocus();
    com.kksoft.readcm.objects.l ls=null;
    if (com.kksoft.readcm.a.Appconfig.getThis().getItemAppObservable().p())
    	ls = com.kksoft.readcm.a.Appconfig.getThis().getItemAppObservable().q();
    com.kksoft.readcm.a.Appconfig.getThis().getItemAppObservable().r();
    P();
    a(1);
    z();
    u();
    a(ls);
    w();
  }

  private boolean M()
  {
	  boolean flag;
      if(g() && O)
          flag = true;
      else
          flag = false;
      return flag;
  }

  private void N()
  {
    SharedPreferences localSharedPreferences1 = App.getSharedPreferences();
    String str1 = String.valueOf(x());
    String str2 = str1 + "Time";
    long l1 = localSharedPreferences1.getLong(str2, 0L) + 300000L;
    long l2 = System.currentTimeMillis();
    if (l1 > l2)
    {
      SharedPreferences localSharedPreferences2 = App.getSharedPreferences();
      String str3 = x();
      String str4 = this.edtFilter.getText().toString();
      String str5 = localSharedPreferences2.getString(str3, str4);
      this.edtFilter.setText(str5);
    }
  }

  private ac P()
  {
	  if(g())
      {
          boolean flag = App.getSharedPreferences().getBoolean("excludeTagged", false);
          O = flag;
      }
      int i1 = H();
      String s1 = A().toString();
      boolean flag1 = M();
      boolean flag2;
      if(h())
          flag2 = false;
      else
          flag2 = true;
      L = new com.kksoft.readcm.objects.ac(i1, s1, flag1, flag2);
      return L;
  }
  
  static ProgressDialog a(ListViewActivity listviewactivity)
  {
      return listviewactivity.pDialog;
  }

  static void b(ListViewActivity listviewactivity)
  {
      listviewactivity.pDialog = null;
  }

  private boolean b(Bundle bundle)
  {
	  int i1 = 0;
	    int i2;
	    if (bundle == null)
	      i2 = 0;
	    else
	    {
	      i2 = bundle.getInt("bulkEditSize");
	      if (i2 > 0)
	      {
	        b(1);
	        while (true)
	        {
	          if (i1 >= i2);
	          ReadListAdapter localo;
	          int i3;
	          do
	          {
	            p();
	            i2 = 1;
	            //break;
	            localo = this.readlistadapter;
	            String str = "bulkEditItem" + i1;
	            i3 = bundle.getInt(str);
	          }
	          while (!localo.b(i3));
	          i1 += 1;
	        }
	      }
	      i2 = 0;
	    }
	    if (i2==0) return false; else return true;
  }

  protected final String A()
  {
    return this.edtFilter.getText().toString();
  }

  protected void B()
  {
    if (this.readlistadapter != null)
    {
    	ReadListAdapter localo = this.readlistadapter;
      String str = A();
      localo.a(str);
    }
  }

  protected int C()
  {
    return R.drawable.ic_menu_markmultiple;
  }

  protected String getMarkStr()     //old D
  {
    return getString(R.string.mu_mark_many);
  }

  protected boolean E()
  {
    return true;
  }

  protected final void F()
  {
    this.listview.setSelection(0);
  }

  public void G()
  {
  }

  public int H()
  {
    if (this.o == 0)
    {
      SharedPreferences localSharedPreferences = App.getSharedPreferences();
      String str = e();
      int i1 = localSharedPreferences.getInt(str, 1);
      this.o = i1;
    }
    return this.o;
  }

  public final void I()
  {
    u();
  }

  public final ac J()
  {
    if (this.L == null)
    {
      ac localac = P();
      this.L = localac;
    }
    return this.L;
  }

  protected void a()
  {
    boolean bool = q();
    this.readlistadapter = new ReadListAdapter(this, bool, loadType());
    ListView localListView = this.listview;
    ReadListAdapter localo2 = this.readlistadapter;
    localListView.setAdapter(localo2);
  }

  protected void SetCoustomView(int i)
  {
	  if(i==this.P)
	  {
	        switch(i)
	        {
	        case 1: // '\001'
	            pErrorScreen.a();
	            pErrorScreen.b();
	            pViewFlipper.setDisplayedChild(1);
	            break;

	        case 2: // '\002'
	            pViewFlipper.setDisplayedChild(0);
	            break;

	        case 6: // '\006'
	            pErrorScreen.a();
	            pViewFlipper.setDisplayedChild(1);
	            break;

	        case 3: // '\003'
	            pErrorScreen.a();
	            if(l() != null)
	            {
	                ErrorScreen errorscreen = pErrorScreen;
	                String s1 = l();
	                errorscreen.a(s1);
	            }
	            if(m() != null)
	            {
	                ErrorScreen errorscreen1 = pErrorScreen;
	                String s2 = m();
	                errorscreen1.c(s2);
	            }
	            if(n() != null)
	            {
	                ErrorScreen errorscreen2 = pErrorScreen;
	                String s3 = n();
	                errorscreen2.d(s3);
	            }
	            pErrorScreen.a(new OnClickListener(){

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						ListViewActivity.this.o();
					}
	            	
	            });
	            pViewFlipper.setDisplayedChild(1);
	            break;

	        case 4: // '\004'
	            pErrorScreen.a();
	            if(k())
	            {
	                pErrorScreen.a(getString(R.string.le_filtered_no_match_t));
	            } else
	            {
	                if(l() != null)
	                {
	                    pErrorScreen.a(l());
	                }
	                if(m() != null)
	                {
	                    pErrorScreen.c(m());
	                }
	                if(n() != null)
	                {
	                    pErrorScreen.d(n());
	                }
	                pErrorScreen.a(new OnClickListener(){

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							ListViewActivity.this.o();
						}});
	            }
	            pViewFlipper.setDisplayedChild(1);
	            break;

	        case 5: // '\005'
	            pViewFlipper.setDisplayedChild(0);
	            break;
	        }
	  }
	  
  }

  protected void a(ContextMenu contextmenu, AdapterView.AdapterContextMenuInfo adaptercontextmenuinfo)
  {
	  contextmenu.add(0, 13, 0, "Mark as Read");
      contextmenu.add(0, 14, 0, "Edit");
      contextmenu.add(0, 16, 0, "Share");
      int i1 = adaptercontextmenuinfo.position;
      if(d(i1).H())
          contextmenu.add(0, 17, 0, "Redownload");
      else
          contextmenu.add(0, 17, 0, "Download");
  }

  protected final void a(Menu paramMenu)
  {
    b(paramMenu);
    if (E())
    {
      String str = getMarkStr();
      MenuItem localMenuItem1 = paramMenu.add(-1, 22, 3, str);
      localMenuItem1.setIcon(C());
    }
    super.a(paramMenu);
  }

  protected void a(l paraml)
  {
    if (paraml != null)
    {
      int i1 = this.readlistadapter.getPosition(paraml);
      if (i1 >= 0)
        this.listview.setSelection(i1);
    }
  }

  protected final void a(boolean paramBoolean)
  {
    n localn = a_();
    this.readlistadapter.a(localn, paramBoolean);
  }

  public final void a(boolean flag, l paraml, String s1, String s2)
  {
	  n = null;
      if(flag)
          if(paraml != null)
          {
              android.content.pm.PackageManager packagemanager = getPackageManager();
              p p1 = new p(paraml, this, packagemanager);
              n = p1;
          } else
          {
              android.content.pm.PackageManager packagemanager1 = getPackageManager();
              p p2 = new p(s1, s2, this, packagemanager1);
              n = p2;
          }
  }

  protected void a(boolean flag, boolean flag1)
  {
    this.K = flag;
    
    if (this.K)
    {
        this.btnSync.setImageDrawable(this.pngBlank);
        progressbar.setVisibility(View.VISIBLE);
        if(!flag1)
        {
            com.kksoft.readcm.a.Appconfig.getThis().d().e();
            com.kksoft.readcm.a.Appconfig.getThis().b().b();
        }
    }
    else
    {
    	this.btnSync.setImageDrawable(pngSync);
        progressbar.setVisibility(View.VISIBLE);
        if(!flag1)
        {
        	com.kksoft.readcm.a.Appconfig.getThis().b().e();
        	com.kksoft.readcm.a.Appconfig.getThis().d().b();
        }
    }
    v();

  }

  protected final boolean a(MenuItem menuitem)
  {
    switch (menuitem.getItemId())
    {
    default:
      return super.a(menuitem);
    case 22:
    	 b(true);
    	 return  true;
    case 23:
    	return  super.a(menuitem);
    case 24:
    	Intent intent2 = new Intent(this, ReadingListActivity.class);
        startActivity(intent2);
        overridePendingTransition(0, 0);
        finish();
        return  true;
    case 25:
    	Intent intent = new Intent(this, CurrentListActivity.class);
        startActivity(intent);
        overridePendingTransition(0, 0);
        finish();
        return  true;
    case 26:
    	 Intent intent1 = new Intent(this, ReadListActivity.class);
         startActivity(intent1);
         overridePendingTransition(0, 0);
         finish();
         return  true;
    }
  }

  protected boolean a(MenuItem paramMenuItem, AdapterView.AdapterContextMenuInfo paramAdapterContextMenuInfo)
  {
    boolean bool=false;
    switch (paramMenuItem.getItemId())
    {
    default:
      bool = super.onContextItemSelected(paramMenuItem);
      break;
    case 13:
        e(paramAdapterContextMenuInfo.position);
        bool=true;
    	break;
      case 14:
    	  Intent intent = new Intent(this, EditItemActivity.class);
          int j1 = paramAdapterContextMenuInfo.position;
          int k1 = d(j1).a();
          intent.putExtra("item_id", k1);
          startActivity(intent);
          bool=true;
    	break;
      case 15:
    	  bool = super.onContextItemSelected(paramMenuItem);
      	break;
      case 16:
    	  if(n == null)
          {
              int l1 = paramAdapterContextMenuInfo.position;
              l l2 = d(l1);
              android.content.pm.PackageManager packagemanager = getPackageManager();
              p p1 = new p(l2, this, packagemanager);
              n = p1;
          }
    	  bool=true;
      	break;
      case 17:
    	  if(!App.isConnectNet())
          {
              showDialog(1);
              bool=true;
          } else
          {
              
              int i2 = paramAdapterContextMenuInfo.position;
              l l3 = d(i2);
              boolean flag;
              boolean flag1;
              if(l3.C() == 0 && !com.kksoft.readcm.activity.App.isDownWeb())
                  flag = false;
              else
                  flag = true;
              if(l3.D() == 0 && !App.isDownText())
                  flag1 = false;
              else
                  flag1 = true;
              if(!flag && !flag1)
                  flag1 = true;
              com.kksoft.readcm.a.Appconfig.getThis().d().a(l3, flag, flag1, false);
              bool=true;
          }
      	break;
    }
    return bool;
  }

  protected n a_()
  {
    return null;
  }

  protected void b()
  {
  }

  protected void b(int paramInt)
  {
    this.o = paramInt;
    SharedPreferences.Editor localEditor = App.getSharedPreferences().edit();
    String str = e();
    localEditor.putInt(str, paramInt).commit();
    this.readlistadapter.a(paramInt);
    F();
  }

  protected void b(Menu paramMenu)
  {
  }

  protected final void b(l paraml)
  {
	  if(!com.kksoft.readcm.activity.App.isConnectNet() && com.kksoft.readcm.objects.u.a(paraml.e()) != null)
      {
          showDialog(24);
      } else
      {
    	  ItemAppObservable e1 = com.kksoft.readcm.a.Appconfig.getThis().getItemAppObservable();
          int i1 = j();
          ac ac1 = J();
          String s1 = b;
          e1.a(i1, ac1, paraml, s1);
          Intent intent = new Intent(this, ReaderActivity.class);
          String s2 = paraml.c();
          intent.putExtra("item_url", s2);
          startActivity(intent);
      }
  }

  protected void b(boolean flag)
  {
	  readlistadapter.a(flag);
      if(!flag)
      {
          this.c.setText(f());
          p2ViewFlipper.setDisplayedChild(0);
          registerForContextMenu(this.listview);
      } else
      {
          StringBuilder stringbuilder = new StringBuilder("Edit ").append(f());
          this.c.setText(stringbuilder.toString());
          p2ViewFlipper.setDisplayedChild(1);
          p();
          unregisterForContextMenu(this.listview);
      }
  }

  protected final int c(int paramInt)
  {
    int i1 = this.M;
    return paramInt - i1;
  }

  protected void c()
  {
  }

  protected final l d(int paramInt)
  {
	  ReadListAdapter localo = this.readlistadapter;
    int i1 = this.M;
    int i2 = paramInt - i1;
    return (l)localo.getItem(i2);
  }

  protected String e()
  {
    return "sortReading";
  }

  protected void e(int paramInt)
  {
    com.kksoft.readcm.a.Appconfig.getThis().getItemAppObservable().a(d(paramInt), false, true);
  }

  protected String f()
  {
    return this.z;
  }

  protected boolean g()
  {
    return false;
  }

  protected boolean h()
  {
    return true;
  }

  protected boolean i()
  {
    return com.kksoft.readcm.a.Appconfig.getThis().b().a(true);
  }

  protected int j()
  {
    return 0;
  }

  protected boolean k()
  {
    return true;
  }

  protected String l()
  {
    return getString(R.string.le_reading_list_t);
  }

  protected String m()
  {
    return getString(R.string.le_reading_list_m);
  }

  protected String n()
  {
    return getString(R.string.le_reading_list_b);
  }

  protected void o()
  {
  }

  public void onBackPressed()
  {
	  if(readlistadapter.f())
          b(false);
      else
          super.onBackPressed();
  }

  public boolean onContextItemSelected(MenuItem menuItem)
  {
	  android.widget.AdapterView.AdapterContextMenuInfo adaptercontextmenuinfo = (android.widget.AdapterView.AdapterContextMenuInfo)menuItem.getMenuInfo();
      boolean flag;
      if(!a(menuItem, adaptercontextmenuinfo) && !super.onContextItemSelected(menuItem))
          flag = false;
      else
          flag = true;
      return flag;
  }

  public void onCreate(Bundle bundle)
  {
    super.onCreate(bundle);
    this.s = true;
    this.m = new Handler();
    
    TextView tvTitle = (TextView)findViewById(R.id.list_title);
    this.c = tvTitle;
    tvTitle.setOnClickListener(new OnClickListener(){

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			ListViewActivity.this.F();
		}
    	
    });
       
    this.p2ViewFlipper = (FixedViewFlipper)findViewById(R.id.list_options_flipper);
    this.p2ViewFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_in));
    this.p2ViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_out));

    this.pngSync = getResources().getDrawable(R.drawable.ic_sync);
    this.pngBlank = getResources().getDrawable(R.drawable.ic_blank);
   
    this.btnSync = (ImageButton)findViewById(R.id.button_sync);
    this.btnSync.setOnClickListener(new OnClickListener(){

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			ListViewActivity.this.y();
		}
    	
    });
    
    this.progressbar = (ProgressBar)findViewById(R.id.sync_progress);
   
    this.btnSort = (ImageButton)findViewById(R.id.button_sort);;
    this.btnSort.setOnClickListener(new OnClickListener(){

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			ListViewActivity.this.showDialog(21);
		}
    	
    });
    
    this.bgFilter = getResources().getDrawable(R.drawable.sel_field_filter);
    this.bgFilterActive = getResources().getDrawable(R.drawable.sel_field_filter_active);
    
    this.icFilter = (ImageView)findViewById(R.id.list_filter_icon);

    this.btnClear = (ImageButton)findViewById(R.id.button_clear);
    this.btnClear.setOnClickListener(new OnClickListener(){

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			ListViewActivity.this.edtFilter.setText("");
		}
    	
    });
    
    this.edtFilter = (EditText)findViewById(R.id.edittext_filter);
    edtFilter.addTextChangedListener(new TextWatcher(){

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onTextChanged(CharSequence s, int start, int before,
				int count) {
			// TODO Auto-generated method stub
			ListViewActivity.this.B();
		}

		@Override
		public void afterTextChanged(Editable s) {
			// TODO Auto-generated method stub
			ListViewActivity.this.w();
		}
    	
    });
    edtFilter.setOnEditorActionListener(new OnEditorActionListener(){

		@Override
		public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
			// TODO Auto-generated method stub
			ListViewActivity.this.edtFilter.clearFocus();
		    return false;
		}
    	
    });
    this.edtFilter.setOnFocusChangeListener(new OnFocusChangeListener(){

		@Override
		public void onFocusChange(View v, boolean hasFocus) {
			// TODO Auto-generated method stub
			if (hasFocus)
		    	  ((InputMethodManager)ListViewActivity.this.getSystemService("input_method")).showSoftInput(v, 1);
		}
    	
    });

    Button btnCancel = (Button)findViewById(R.id.bulk_cancel);
    //this.J = btnCancel;
    btnCancel.setOnClickListener(new OnClickListener(){

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			ListViewActivity.this.b(0);
		}
    	
    });
    
    Button btnAction = (Button)findViewById(R.id.bulk_action);
    this.j = btnAction;
    btnAction.setOnClickListener(new OnClickListener(){

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			ListViewActivity.c(ListViewActivity.this);
		}
    	
    });
    
    this.pViewFlipper = (FixedViewFlipper)findViewById(R.id.list_flipper);;
    this.listview= (ListView)findViewById(R.id.list);;
     this.listview.setOnItemClickListener(new OnItemClickListener(){

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			// TODO Auto-generated method stub
			if(ListViewActivity.this.c(position) < 0)
				ListViewActivity.this.t();
	        else
	        if(!ListViewActivity.this.readlistadapter.f())
	        {
	            com.kksoft.readcm.objects.l l1 = ListViewActivity.this.d(position);
	            ListViewActivity.this.b(l1);
	        } else
	        {
	            com.kksoft.readcm.objects.l l2 = ListViewActivity.this.d(position);
	            ListViewActivity.this.readlistadapter.a(l2, view);
	            ListViewActivity.this.p();
	        }
		}
    	
    });
    registerForContextMenu(this.listview);
    
    ErrorScreen errorscreen = (ErrorScreen)findViewById(R.id.list_errors);
    this.pErrorScreen = errorscreen;
    LinearLayout llHeader = (LinearLayout)View.inflate(this, R.layout.list_header_container, null);
    this.d = llHeader;
    this.listview.addHeaderView(llHeader);

    M = M + 1;
    b();
    c();
    a();
    
    tvTitle.setText(f());
    b(bundle);
    N();
    L();
  }

  public void onCreateContextMenu(ContextMenu paramContextMenu, View paramView, ContextMenu.ContextMenuInfo paramContextMenuInfo)
  {
    AdapterView.AdapterContextMenuInfo localAdapterContextMenuInfo = (AdapterView.AdapterContextMenuInfo)paramContextMenuInfo;
    int i1 = localAdapterContextMenuInfo.position;
    String str = d(i1).l();
    paramContextMenu.setHeaderTitle(str);
    a(paramContextMenu, localAdapterContextMenuInfo);
  }

  protected Dialog onCreateDialog(int paramInt)
  {
    switch (paramInt)
    {
    default:
    	return super.onCreateDialog(paramInt);
    case 21:
    	AlertDialog.Builder builder = new AlertDialog.Builder(this);
    	builder.setTitle(getString(R.string.dg_sort_t))
    			.setSingleChoiceItems(com.kksoft.readcm.d.j.a(),H()-1,new DialogInterface.OnClickListener(){

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						dialog.dismiss();
					    ListViewActivity.this.b(which+1);
					}
    				
    			});

        Dialog dialog=builder.create();
        dialog.setCanceledOnTouchOutside(true);
        return dialog;
    case 22:
    	return super.onCreateDialog(paramInt);
    case 23:
    	ProgressDialog progressdialog = new ProgressDialog(this);
        pDialog = progressdialog;
        pDialog.setMessage("Saving...");
        pDialog.setIndeterminate(true);
        pDialog.setCancelable(false);
        return pDialog;
    case 24:
    	AlertDialog.Builder builder2 =new AlertDialog.Builder(this);
    	builder2.setTitle(R.string.dg_offline_video_t).setMessage(R.string.dg_offline_video_m)
    	.setNeutralButton(R.string.ac_ok,new DialogInterface.OnClickListener(){

			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				dialog.dismiss();
			}
    		
    	});
    	Dialog dialog1=builder2.create();
        dialog1.setCanceledOnTouchOutside(true);
        return dialog1;
    }
  }

  public void onPause()
  {
    super.onPause();
    this.N = false;
    App.getSharedPreferences().edit()
    .putString(x(), this.edtFilter.getText().toString())
    .putLong(String.valueOf(x()) + "Time", System.currentTimeMillis()).commit();
  }

  public boolean onPrepareOptionsMenu(Menu menu)
  {
	  super.onPrepareOptionsMenu(menu);
      if(E())
      {
          MenuItem menuitem = menu.findItem(22);
          boolean flag1;
          if(!readlistadapter.f() && P != 3)
              flag1 = true;
          else
              flag1 = false;
          menuitem.setEnabled(flag1);
      }
      return true;
  }

  protected void onRestart()
  {
    N();
    super.onRestart();
    L();
  }

  public void onResume()
  {
    super.onResume();
    if (!this.N)
      L();
  }

  protected void onSaveInstanceState(Bundle bundle)
  {
	  if(!readlistadapter.f() || readlistadapter.e() <= 0)
	  {
		  super.onSaveInstanceState(bundle);
	  }
	  else
	  {
		  Iterator iterator;
          int j1;
          int i1 = readlistadapter.d().size();
          bundle.putInt("bulkEditSize", i1);
          iterator = readlistadapter.d().entrySet().iterator();
          j1 = 0;
          while(iterator.hasNext())
          {
        	  java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next();
	          String s1 = (new StringBuilder("bulkEditItem")).append(j1).toString();
	          int k1 = ((Integer)entry.getKey()).intValue();
	          bundle.putInt(s1, k1);
	          j1++;
          }
	  }
  }

  public boolean onSearchRequested()
  {
    this.edtFilter.requestFocus();
    return false;
  }

  public void onStop()
  {
    super.onStop();
    if (this.readlistadapter != null)
      this.readlistadapter.g();
    this.edtFilter.clearFocus();
  }

  protected void p()
  {
	  String s1;
      Button button;
      String s2;
      Object aobj[];
      String s3;
      if(readlistadapter.d() != null)
          s1 = String.valueOf(readlistadapter.d().size());
      else
          s1 = "0";
      button = j;
      s2 = getString(R.string.ac_bulk_mark_items);
      aobj = new Object[1];
      aobj[0] = s1;
      s3 = String.format(s2, aobj);
      button.setText(s3);
  }

  protected boolean q()
  {
    return false;
  }

  protected int loadType()          //old r
  {
    return 2;
  }

  protected final int getLayoutID()   //old s
  {
    return R.layout.activity_list;
  }

  protected void t()
  {
  }

  public void u()
  {
	  if(readlistadapter.getCount() > 0)
          a(2);
      else
      if(readlistadapter.a() > 0)
      {
          if(readlistadapter.c())
              a(2);
          else
          if(A().length() > 0)
              a(4);
          else
          if(M())
              a(5);
          else
              a(2);
      } else
      if(com.kksoft.readcm.a.Appconfig.getThis().l())
          a(1);
      else
      if(i())
          a(6);
      else
          a(3);
      v();
  }


  public void update(Observable observable, final Object obj)
  {
	  runOnUiThread(new Runnable(){

		@Override
		public void run() {
			// TODO Auto-generated method stub
			switch(GlobalVar.a(obj).a())
			{
				default:
					break;
				case 1:
					ListViewActivity.this.a(false);
					break;
				case 2:
					ListViewActivity.this.a(false);
					break;
				case 3:
					ListViewActivity.this.p = false;
					ListViewActivity.this.a(false);
					break;
				case 11:
					ReadListAdapter o1 = ListViewActivity.this.readlistadapter;
			        String s = GlobalVar.a(obj).b();
			        o1.a(s);
			        break;
				case 20:
				case 21:
				case 30:
				case 35:
					ListViewActivity.this.z();
					break;
			}
		}	 
		  
	  });
      super.update(observable, obj);
  }

  protected void v()
  {
  }

  protected final void w()
  {
	  if(edtFilter.getText().length() > 0)
      {
		  this.btnClear.setVisibility(View.VISIBLE);
          this.edtFilter.setBackgroundDrawable(this.bgFilterActive);
          this.icFilter.setEnabled(true);
      } else
      {
    	  this.btnClear.setVisibility(View.GONE);
          this.edtFilter.setBackgroundDrawable(this.bgFilter);
          this.icFilter.setEnabled(false);
      }
  }

  protected String x()
  {
    return "filterReading";
  }

  protected final void y()
  {
	  boolean flag;
      if(K)
          flag = false;
      else
          flag = true;
      a(flag, false);
  }

  protected final void z()
  {
	  if(com.kksoft.readcm.a.Appconfig.getThis().b().a(true) || com.kksoft.readcm.a.Appconfig.getThis().d().c())
          a(true, true);
      else
          a(false, true);
  }
}